﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LMSGridLibrary
{
    public static class Shell
    {
        public static string LastError;

        public static string run(string cmd, string args)
        {
            string output = null;
            try
            {
                var processo = new System.Diagnostics.Process
                                   {
                                       EnableRaisingEvents = false,
                                       StartInfo =
                                           {
                                               FileName = cmd,
                                               Arguments = args,
                                               RedirectStandardOutput = true,
                                               RedirectStandardError = true,
                                               UseShellExecute = false
                                           }
                                   };
                processo.Start();
                if (!processo.HasExited)
                    processo.WaitForExit();

                output = processo.StandardOutput.ReadToEnd();
                LastError = processo.StandardError.ReadToEnd();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            return output;
        }
    }
}
